home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / SciAn / src / ScianRecorders.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  30KB  |  1,092 lines

  1. /*ScianRecorders.c
  2.   Eric Pepke
  3.   Operates recorders from within scian
  4. */
  5.  
  6. #include "Scian.h"
  7. #include "ScianTypes.h"
  8. #include "ScianIDs.h"
  9. #include "ScianWindows.h"
  10. #include "ScianObjWindows.h"
  11. #include "ScianDialogs.h"
  12. #include "ScianScripts.h"
  13. #include "ScianErrors.h"
  14. #include "ScianSymbols.h"
  15. #include "ScianLists.h"
  16. #include "ScianControls.h"
  17. #include "ScianButtons.h"
  18. #include "ScianTextBoxes.h"
  19. #include "ScianTitleBoxes.h"
  20. #include "ScianIcons.h"
  21. #include "ScianStyle.h"
  22. #include "ScianObjFunctions.h"
  23. #include "ScianDatabase.h"
  24. #include "ScianGarbageMan.h"
  25. #include "ScianScrDump.h"
  26. #include "ScianRecorders.h"
  27. #include "ScianColors.h"
  28. #include "ScianObjFunctions.h"
  29. #include "ScianTemplates.h"
  30. #include "ScianTemplateHelper.h"
  31. #include "ScianLVR5000.h"
  32. #include "ScianTQ2026F.h"
  33. #include "ScianJpeg.h"
  34. #include "ScianSnap.h"
  35.  
  36. ObjPtr curRecorder = NULLOBJ;        /*Current recorder*/
  37. Bool recordEnabled = false;        /*True iff recording is enabled*/
  38. extern double videoClock;        /*Clock for the duration of the video*/
  39. real fps = 30.0;            /*Default is 30 fps*/
  40. Bool recording = false;            /*True iff recording*/
  41. ObjPtr recorderClass;            /*Class of all recorders*/
  42. ObjPtr commRecorderClass;        /*Class of recorders that do comm*/
  43.  
  44. #ifdef PROTO
  45. ObjPtr NewRecorder(ObjPtr class, char *name, char *brandName)
  46. #else
  47. ObjPtr NewRecorder(class, name, brandName)
  48. ObjPtr class;
  49. char *name;
  50. char *brandName;
  51. #endif
  52. {
  53.     ObjPtr retVal;
  54.  
  55.     retVal = NewObject(class ? class : recorderClass, 0L);
  56.     SetVar(retVal, NAME, NewString(name));
  57.     SetVar(retVal, BRANDNAME, NewString(brandName));
  58.     return retVal;
  59. }
  60.  
  61. #ifdef PROTO
  62. void RegisterRecorder(ObjPtr recorder)
  63. #else
  64. void RegisterRecorder(recorder)
  65. ObjPtr recorder;
  66. #endif
  67. {
  68.     AddObjToDatabase(recorder);
  69.     ApplySavedSettings(recorder);
  70.     if (!curRecorder)
  71.     {
  72.     curRecorder = recorder;
  73.     }
  74. }
  75.  
  76. #ifdef PROTO
  77. Bool SetRecorder(char *name) 
  78. #else
  79. Bool SetRecorder(name)
  80. char *name;
  81. #endif
  82. /*Sets the current recorder to a recorder named name*/
  83. {
  84.     int k;
  85.     ObjPtr allRecorders;
  86.     ObjPtr keyList;
  87.     ThingListPtr runner;
  88.  
  89.     if (logging)
  90.     {
  91.     char cmd[256];
  92.     char *s;
  93.  
  94.     sprintf(cmd, "set recorder ");
  95.     s = &(cmd[0]);
  96.     while (*s) ++s;
  97.     *s++ = ' ';
  98.     s = PrintScriptString(s, name);
  99.     *s++ = '\n';
  100.     *s = 0;
  101.     Log(cmd);
  102.     }
  103.  
  104.     keyList = NewList();
  105.     PostfixList(keyList, NewSymbol(CLASSID));
  106.     PostfixList(keyList, NewInt(CLASS_RECORDER));
  107.  
  108.     allRecorders = SearchDatabase(keyList);
  109.     if (allRecorders)
  110.     {
  111.     runner = LISTOF(allRecorders);
  112.  
  113.     while (runner)
  114.     {
  115.          ObjPtr var, curName;
  116.         curName = GetStringVar("SetRecorder", runner -> thing, NAME);
  117.         if (curName)
  118.         {
  119.         /*Test name*/
  120.         if (0 == strcmp2(GetString(curName), name))
  121.         {
  122.             /*It's a match*/
  123.             curRecorder = runner -> thing;
  124.             return true;
  125.         }
  126.  
  127.         /*Test brand name plus name*/
  128.         var = GetVar(runner -> thing, BRANDNAME);
  129.         if (var)
  130.         {
  131.             strcpy(tempStr, GetString(var));
  132.             strcat(tempStr, " ");
  133.             strcat(tempStr, GetString(curName));
  134.         }
  135.         }
  136.         runner = runner -> next;
  137.     }
  138.     }
  139.     return false;
  140. }
  141.  
  142. #ifdef PROTO
  143. void SetFPS(real newFPS)
  144. #else
  145. void SetFPS(newFPS)
  146. void newFPS;
  147. #endif
  148. /*Sets the number of frames per second to newFPS*/
  149. {
  150.     if (curRecorder)
  151.     {
  152.     SetVar(curRecorder, FRAMERATE, NewReal(newFPS));
  153.     ImInvalid(curRecorder);
  154.     }
  155. }
  156.  
  157. #ifdef PROTO
  158. void SetScreenSize(int x, int y)
  159. #else
  160. void SetScreenSize(x, y)
  161. int x, y;
  162. #endif
  163. {
  164.     if (curRecorder)
  165.     {
  166.     SetVar(curRecorder, FRAMEWIDTH, NewInt(x));
  167.     SetVar(curRecorder, FRAMEHEIGHT, NewInt(y));
  168.     }
  169. }
  170.  
  171. #ifdef PROTO
  172. void GetScreenSize(int *x, int *y)
  173. #else
  174. void GetScreenSize(*x, *y)
  175. int *x, *y;
  176. #endif
  177. {
  178.     if (curRecorder)
  179.     {
  180.     ObjPtr var;
  181.  
  182.     var = GetIntVar("GetScreenSize", curRecorder, FRAMEWIDTH);
  183.     if (var)
  184.     {
  185.         *x = GetInt(var);
  186.     }
  187.     else
  188.     {
  189.         *x = VSCRWIDTH;
  190.     }
  191.  
  192.     var = GetIntVar("GetScreenSize", curRecorder, FRAMEHEIGHT);
  193.     if (var)
  194.     {
  195.         *y = GetInt(var);
  196.     }
  197.     else
  198.     {
  199.         *y = VSCRHEIGHT;
  200.     }
  201.     }
  202.     else
  203.     {
  204.     *x = VSCRWIDTH;
  205.     *y = VSCRHEIGHT;
  206.     }
  207. }
  208.  
  209. Bool PrepareToRecord(nFrames)
  210. int nFrames;
  211. /*Prepares to record nFrames*/
  212. {
  213.     int retVal;
  214.     FuncTyp method;
  215.     ObjPtr var;
  216.  
  217.     if (!curRecorder)
  218.     {
  219.     return false;
  220.     }
  221.     var = GetRealVar("PrepareToRecord", curRecorder, FRAMERATE);
  222.     if (!var)
  223.     {
  224.     fps = 30.0;
  225.     }
  226.     else
  227.     {
  228.     fps = GetReal(var);
  229.     }
  230.  
  231.     SetSystemClock(0.0);
  232.     if (recordEnabled)
  233.     {
  234.     method = GetMethod(curRecorder, PREPARETORECORD);
  235.     if (method)
  236.     {
  237.         return IsTrue((*method)(curRecorder, nFrames)) ? true : false;
  238.     }
  239.     }
  240.     else
  241.     {
  242.     return true;
  243.     }
  244.     return false;
  245. }
  246.  
  247. static int rwl, rwr, rwb, rwt;
  248. static ObjPtr rwList;
  249.  
  250. void ExpandRecorderScreen(window)
  251. WinInfoPtr window;
  252. /*Expands the recorder screen for window*/
  253. {
  254.     int l, r, b, t, ox, oy, w, h;
  255.  
  256.     PostfixList(rwList, (ObjPtr) window);
  257.  
  258.     SelWindow(window);
  259.     GetWindowBounds(&l, &r, &b, &t);
  260.     GetWindowOrigin(&ox, &oy);
  261.     w = r - l;
  262.     h = t - b;
  263.     if (ox < rwl) rwl = ox;
  264.     if (ox + w > rwr) rwr = ox + w;
  265.     if (oy < rwb) rwb = oy;
  266.     if (oy + h > rwt) rwt = oy + h;
  267. }
  268.  
  269. #ifdef PROTO
  270. Bool AdjustToVisWindows(ObjPtr recorder)
  271. #else
  272. Bool AdjustToVisWindows(recorder)
  273. ObjPtr recorder;
  274. #endif
  275. /*Adjusts recorder to all vis windows.  Returns true iff it worked*/
  276. {
  277.     ObjPtr var;
  278.  
  279.     MakeVar(recorder, FRAMESOURCE);
  280.     var = GetIntVar("AdjustToVisWindows", recorder, FRAMESOURCE);
  281.     if (!var) return true;
  282.  
  283.     if (GetInt(var) == FS_WINDOW)
  284.     {
  285.     /*Set the bounds to be impossible*/
  286.     rwr = -20000;
  287.     rwt = -20000;
  288.     rwl = 20000;
  289.     rwb = 20000;
  290.  
  291.     rwList = NewList();
  292.  
  293.     /*Expand the bounds*/
  294.     ForAllVisWindows(ExpandRecorderScreen);
  295.  
  296.     /*See if there were no windows*/
  297.     if (rwl >= rwr || rwb >= rwt) return false;
  298.  
  299.     /*Must have been windows.  Set it.*/
  300.     SetVar(recorder, FRAMEWIDTH, NewInt(rwr - rwl));
  301.     SetVar(recorder, FRAMEHEIGHT, NewInt(rwt - rwb));
  302.     SetVar(recorder, FRAMEOX, NewInt(rwl));
  303.     SetVar(recorder, FRAMEOY, NewInt(rwb));
  304.  
  305.     SetVar(recorder, RECORDWINDOWS, rwList);
  306.     }
  307.     return true;
  308. }
  309.  
  310. #ifdef PROTO
  311. Bool AdjustToCurWindow(ObjPtr recorder)
  312. #else
  313. Bool AdjustToCurWindow(recorder)
  314. ObjPtr recorder;
  315. #endif
  316. /*Adjusts recorder to the current window.  Returns true iff it worked*/
  317. {
  318.     ObjPtr var;
  319.  
  320.     MakeVar(recorder, FRAMESOURCE);
  321.     var = GetIntVar("AdjustToCurWindow", recorder, FRAMESOURCE);
  322.     if (!var) return true;
  323.  
  324.     if (GetInt(var) == FS_WINDOW)
  325.     {
  326.     int l, r, b, t, ox, oy, w, h;
  327.  
  328.     GetWindowBounds(&l, &r, &b, &t);
  329.     GetWindowOrigin(&ox, &oy);
  330.     w = r - l;
  331.     h = t - b;
  332.  
  333.     /*Must be a window.  Set it.*/
  334.     SetVar(recorder, FRAMEWIDTH, NewInt(w));
  335.     SetVar(recorder, FRAMEHEIGHT, NewInt(h));
  336.     SetVar(recorder, FRAMEOX, NewInt(ox));
  337.     SetVar(recorder, FRAMEOY, NewInt(oy));
  338.  
  339.     rwList = NewList();
  340.     PostfixList(rwList, (ObjPtr) selWinInfo);
  341.     SetVar(recorder, RECORDWINDOWS, rwList);
  342.     }
  343.     return true;
  344. }
  345.  
  346. Bool ConnectRecorder()
  347. /*Connects to the current recorder*/
  348. {
  349.     int retVal;
  350.     FuncTyp method;
  351.  
  352.     if (recordEnabled)
  353.     {
  354.     method = GetMethod(curRecorder, CONNECT);
  355.     if (method)
  356.     {
  357.         Bool truth;
  358.         truth = IsTrue((*method)(curRecorder)) ? true : false;
  359.         return truth;
  360.     }
  361.     return false;
  362.     }
  363.     else
  364.     {
  365.     printf("This is a dry run.  Status messages will be printed, but no actual recording\n");
  366.     printf("will be done.  To record for real, rerun SciAn including the -v flag on the\n");
  367.     printf("command line.\n");
  368.     return true;
  369.     }
  370. }
  371.  
  372. Bool StopRecording()
  373. /*Stops recording on the current recorder*/
  374. {
  375.     int retVal;
  376.     FuncTyp method;
  377.  
  378.     MySetCursor(0);
  379.     SetSystemClock(0.0);
  380.     if (recordEnabled)
  381.     {
  382.     method = GetMethod(curRecorder, STOPRECORDING);
  383.     if (method)
  384.     {
  385.         return IsTrue((*method)(curRecorder)) ? true : false;
  386.     }
  387.     }
  388.     else
  389.     {
  390.     return true;
  391.     }
  392.     return false;
  393. }
  394.  
  395. #ifdef PROTO
  396. void Delay(double time)
  397. #else
  398. void Delay(time)
  399. double time;
  400. #endif
  401. /*Delays for time seconds*/
  402. {
  403.     struct tms buffer;
  404.     long started;
  405.  
  406.     started = times(&buffer);
  407.     do
  408.     {
  409.     } while (times(&buffer) - started < (long) (time * HEARTBEAT));
  410. }
  411.  
  412. Bool SnapOneFrame()
  413. /*Snaps a single frame shot on the current recorder*/
  414. {
  415.     int retVal = false;
  416.     FuncTyp method;
  417.  
  418.     MySetCursor(-1);
  419.  
  420.     if (recordEnabled)
  421.     {
  422.     Delay(0.2);
  423.  
  424.     method = GetMethod(curRecorder, SNAPONEFRAME);
  425.     if (method)
  426.     {
  427.         retVal = IsTrue((*method)(curRecorder)) ? true : false;
  428.     }
  429.     }
  430.     else
  431.     {
  432.     retVal = true;
  433.     printf("Snap at %lg\n", videoClock);
  434.     }
  435.     if (retVal)
  436.     {
  437.     videoClock += 1.0 / fps;
  438.     }
  439.     return retVal;
  440. }
  441.  
  442. void DisconnectRecorder()
  443. /*Connects to the current recorder*/
  444. {
  445.     int retVal;
  446.     FuncTyp method;
  447.  
  448.     if (recordEnabled)
  449.     {
  450.     method = GetMethod(curRecorder, DISCONNECT);
  451.     if (method)
  452.     {
  453.         (*method)(curRecorder);
  454.     }
  455.     }
  456. }
  457.  
  458. static ObjPtr HideRecorderDriversWindow(window)
  459. ObjPtr window;
  460. /*Hide a recorder drivers window, just return OK*/
  461. {
  462.     return ObjTrue;
  463. }
  464.  
  465. WinInfoPtr NewRecorderDriversWindow(void)
  466. /*Create a new recorder drivers window*/
  467. {
  468.     WinInfoPtr objWin;
  469.     ThingListPtr runner;
  470.     ObjPtr panel, contents, corral, button;
  471.     int bw;
  472.     int l, r, b, t;
  473.     ObjPtr allRecorderDrivers;
  474.     ObjPtr keyList;
  475.  
  476.     /*Create the window*/
  477.     objWin = NewObjWindow(NULLOBJ, "Recorder Drivers", WINUI, RDWINWIDTH, RDWINHEIGHT, SCRWIDTH, SCRHEIGHT);
  478.  
  479.     /*Set a null but successful HIDE routine*/
  480.     SetMethod((ObjPtr) objWin, HIDE, HideRecorderDriversWindow);
  481.  
  482.     /*Add a help string*/
  483.     SetVar((ObjPtr) objWin, HELPSTRING, 
  484.     NewString("This window shows all the recorder drivers in Scian."));
  485.  
  486.     /*Put in a panel*/
  487.     panel = NewPanel(greyPanelClass, 0, RDWINWIDTH, 0, RDWINHEIGHT);
  488.     SetVar(panel, STICKINESS, NewInt(STICKYLEFT + STICKYRIGHT +
  489.                      STICKYBOTTOM + STICKYTOP));
  490.  
  491.     contents = GetVar((ObjPtr) objWin, CONTENTS);
  492.     PrefixList(contents, panel);
  493.     SetVar(panel, PARENT, (ObjPtr) objWin);
  494.  
  495.     l = 0; r = RDWINWIDTH; b = 0; t = RDWINHEIGHT;
  496.  
  497.     /*Put in buttons and an icon corral*/
  498.     contents = GetListVar("NewRecorderDriversWindow", panel, CONTENTS);
  499.     if (!contents)
  500.     {
  501.     return 0;
  502.     }
  503.     /*Make an icon corral*/
  504.     corral = NewIconCorral(NULLOBJ, l + MINORBORDER, r - MINORBORDER, b + 2 * MINORBORDER + BUTTONHEIGHT, t - MINORBORDER, BARRIGHT + BARBOTTOM);
  505.     SetVar(corral, STICKINESS, NewInt(STICKYLEFT + STICKYRIGHT +
  506.                      STICKYBOTTOM + STICKYTOP));
  507.     SetVar(corral, TOPDOWN, ObjTrue);
  508.     SetVar(corral, NAME, NewString("Recorder Drivers Corral"));
  509.     SetVar(corral, HELPSTRING,
  510.     NewString("This corral contains icons for all the recorder drivers in \
  511. SciAn.  Recorder drivers are used to do frame-by-frame recording from a script.  \
  512. The active recorder driver is indicated by a red pilot light on the icon.  \
  513. To change the active recorder, select it and press the Activate button.  To \
  514. show controls for any of the recorders, select them and press the Show Controls \
  515. button."));
  516.     PrefixList(contents, corral);
  517.     SetVar(corral, PARENT, panel);
  518.     SetVar((ObjPtr) objWin, CORRAL, corral);
  519.  
  520.     l += MINORBORDER;
  521.     r -= MINORBORDER;
  522.     b += MINORBORDER;
  523.     t = b + BUTTONHEIGHT;
  524.     bw = (r - l - MINORBORDER) / 2;
  525.  
  526.     /*Make a show info button*/
  527.     button = NewFunctionButton(objWin,
  528.         l, l + bw, 
  529.         b, b + BUTTONHEIGHT, OF_SHOW_CONTROLS); 
  530.     if (button)
  531.     {
  532.     SetVar(button, PARENT, panel);
  533.     SetVar(button, STICKINESS, NewInt(STICKYBOTTOM + STICKYLEFT + FLOATINGRIGHT));
  534.     PrefixList(contents, button);
  535.     }
  536.  
  537.     /*Make an activate recorder function button*/
  538.     button = NewFunctionButton(objWin, r - bw, r, b, b + BUTTONHEIGHT, OF_ACTIVATE);
  539.     if (button)
  540.     {
  541.     SetVar(button, PARENT, panel);
  542.     SetVar(button, STICKINESS, NewInt(STICKYBOTTOM + STICKYRIGHT + FLOATINGLEFT));
  543.     PrefixList(contents, button);
  544.     }
  545.  
  546.     /*Drop all the recorders into the window*/
  547.     keyList = NewList();
  548.     PostfixList(keyList, NewSymbol(CLASSID));
  549.     PostfixList(keyList, NewInt(CLASS_RECORDER));
  550.  
  551.     allRecorderDrivers = SearchDatabase(keyList);
  552.  
  553.     runner = LISTOF(SortListByStringVar(allRecorderDrivers, NAME, true));
  554.  
  555.     while(runner)
  556.     {
  557.     ObjPtr icon, name;
  558.     FuncTyp method;
  559.     
  560.     icon = GetVar(runner -> thing, DEFAULTICON);
  561.     if (!icon)
  562.     {
  563.         icon = NewIcon(0, 0, ICONRECORDER, "?");
  564.     }
  565.     else
  566.     {
  567.         icon = NewObject(icon, 0L);
  568.     }
  569.     name = GetVar(runner -> thing, NAME);
  570.     SetVar(icon, NAME, name);
  571.     SetVar(icon, FORMAT, GetVar(runner -> thing, BRANDNAME));
  572.  
  573.     SetVar(icon, ICONLOC, NULLOBJ);
  574.     SetVar(icon, REPOBJ, runner -> thing);
  575.     SetVar(icon, CORRAL, corral);
  576.     DropIconSeriesInCorral(corral, icon);
  577.  
  578.     runner = runner -> next;
  579.     }
  580.  
  581.     return objWin;
  582. }
  583.  
  584. static ObjPtr ShowRecorderControls(object, windowName)
  585. ObjPtr object;
  586. char *windowName;
  587. /*Makes a new control window to control recorder object*/
  588. {
  589.     WinInfoPtr controlWindow;
  590.     ObjPtr var;
  591.     ObjPtr panel;
  592.     ObjPtr controlField;
  593.     ObjPtr contents;
  594.     ObjPtr curObj;
  595.     ObjPtr firstButton = NULLOBJ;
  596.     int left, right, bottom, top, width;
  597.     WinInfoPtr dialogExists;
  598.     Bool abortp = false;
  599.     Bool saveSettings = false;
  600.  
  601.     dialogExists = DialogExists((WinInfoPtr) object, NewString("Controls"));
  602.     controlWindow = GetDialog((WinInfoPtr) object, NewString("Controls"), windowName, 
  603.     CWINWIDTH, CWINHEIGHT, CWINWIDTH, CWINHEIGHT, WINFIXEDSIZE + WINUI);
  604.     
  605.     if (!dialogExists)
  606.     {
  607.     SetVar((ObjPtr) controlWindow, REPOBJ, object);
  608.  
  609.     /*Add in help string*/
  610.     SetVar((ObjPtr) controlWindow, HELPSTRING,
  611.         NewString("This window shows controls for a recorder driver.  \
  612. At the right is an icon corral showing a series of icons.  Each icon represents a \
  613. set of attributes of the visualization object.  On the left are the controls for \
  614. the selected set of attributes.  \
  615. Use Help In Context and click on the various controls to find out what they do.  \
  616. Click on a different icon to choose a different set of attributes."));
  617.  
  618.     /*Add in a panel*/
  619.     panel = NewPanel(greyPanelClass, 0, CWINWIDTH, 0, CWINHEIGHT);
  620.     if (!panel)
  621.     {
  622.         return ObjFalse;
  623.     }
  624.     contents = GetVar((ObjPtr) controlWindow, CONTENTS);
  625.     PrefixList(contents, panel);
  626.     SetVar(panel, PARENT, (ObjPtr) controlWindow);
  627.  
  628.     contents = GetVar(panel, CONTENTS);
  629.  
  630.     /*Add in a control field*/
  631.     controlField = NewControlField(CWINWIDTH - CORRALBORDER - CWINCORRALWIDTH,
  632.                    CWINWIDTH - CORRALBORDER,
  633.                    CORRALBORDER,
  634.                    CWINHEIGHT - CORRALBORDER,
  635.                 "Recorder Attributes", OBJECTSFROMTOP | BARRIGHT);
  636.     SetVar(controlField, HELPSTRING,
  637.        NewString("This icon button group shows sets of attributes of the recorder \
  638. driver that can be modified.  The left side of the panel shows controls for the \
  639. attribute given by the selected icon button.  To show another set of \
  640. attributes, press another button."));
  641.     SetVar(controlField, PARENT, panel);
  642.     PrefixList(contents, controlField);
  643.  
  644.     contents = GetVar(controlField, CONTENTS);
  645.  
  646.     /*Fill the control field up with buttons*/
  647.     curObj = object;
  648.     top = -MAJORBORDER;
  649.     width = CWINCCWIDTH;
  650.  
  651.     saveSettings = GetPredicate(curObj, CANSAVESETTINGS);
  652.  
  653.  
  654.     while (curObj)
  655.     {
  656.         ObjPtr icon;
  657.         icon = Get1Var(curObj, CONTROLICON);
  658.         if (icon)
  659.         {
  660.         ObjPtr button;
  661.         ObjPtr panelContents;
  662.         FuncTyp method;
  663.         int whichIcon;
  664.         char *name;
  665.  
  666.         if (firstButton && abortp) break;
  667.  
  668.         var = GetIntVar("ShowRecorderControls", icon, WHICHICON);
  669.         if (var)
  670.         {
  671.             whichIcon = GetInt(var);
  672.         }
  673.         else
  674.         {
  675.             whichIcon = ICONQUESTION;
  676.         }
  677.  
  678.         var = GetStringVar("ShowRecorderControls", icon, NAME);
  679.         if (var)
  680.         {
  681.             name = GetString(var);
  682.         }
  683.         else
  684.         {
  685.             name = "Unknown";
  686.         }
  687.  
  688.         button = NewIconLabeledButton(0, width, top - CWINICONBUTHEIGHT, top,
  689.             whichIcon, UIYELLOW, name, BS_PITTED);
  690.         SetMethod(button, ICONEXTRADRAW, GetMethod(icon, ICONEXTRADRAW));
  691.         SetVar(button, REPOBJ, object);
  692.         SetMethod(button, CHANGEDVALUE, ChangeControlPanelButton);
  693.  
  694.         SetVar(button, PANEL, panel);
  695.  
  696.         if (!firstButton)
  697.         {
  698.             firstButton = button;
  699.         }
  700.  
  701.         if (saveSettings)
  702.         {
  703.             SetVar(button, CANSAVESETTINGS, ObjTrue);
  704.         }
  705.         /*Make a new panel contents just for this button*/
  706.         panelContents = NewList();
  707.         PrefixList(panelContents, controlField);
  708.         SetVar(panelContents, PARENT, panel);
  709.         SetVar(button, PANELCONTENTS, panelContents);
  710.         SetVar(button, PARENT, panelContents);
  711.  
  712.         /*Give the button a chance to add controls*/
  713.         method = Get1Method(curObj, ADDCONTROLS);
  714.         if (method)
  715.         {
  716.             SetVar(button, CONTROLSADDED, ObjFalse);
  717.             SetMethod(button, ADDCONTROLS, method);
  718.         }
  719.         else
  720.         {
  721.             SetVar(button, CONTROLSADDED, ObjTrue);
  722.         }
  723.         PrefixList(contents, button);
  724.         SetVar(button, PARENT, controlField);
  725.         top -= CWINICONBUTHEIGHT + MINORBORDER;
  726.     
  727.         }
  728.         if (GetPredicate(curObj, ABORTCONTROLS)) abortp = true;
  729.         curObj = ClassOf(curObj);
  730.     }
  731.  
  732.     /*Adjust the scroll bars*/
  733.     RecalcScroll(controlField);
  734.  
  735.     if (firstButton)
  736.     {
  737.         SetValue(firstButton, NewInt(1));
  738.         SetVar(controlField, BUTTON, firstButton);
  739.     }
  740.     }
  741.  
  742.     return (ObjPtr) controlWindow;
  743. }
  744.  
  745. WinInfoPtr RecorderDriversWindow()
  746. /*Returns or creates a recorder drivers window*/
  747. {
  748.     WinInfoPtr retVal;
  749.  
  750.     retVal = GetWinFromTitle("Recorder Drivers");
  751.     if (!retVal)
  752.     {
  753.     retVal = NewRecorderDriversWindow();
  754.     }
  755.     return retVal;
  756. }
  757.  
  758. WinInfoPtr AnimationControlsWindow()
  759. /*Returns or creates an animation controls window*/
  760. {
  761.     WinInfoPtr retVal;
  762. #if 0
  763.     retVal = GetWinFromTitle("Recorder Drivers");
  764.     if (!retVal)
  765.     {
  766.     retVal = NewRecorderDriversWindow();
  767.     }
  768.     return retVal;
  769. #endif
  770. }
  771.  
  772. static ObjPtr AddFrameControls(object, panelContents)
  773. ObjPtr object, panelContents;
  774. /*Adds frame controls to a panel*/
  775. {
  776.     ObjPtr textBox, titleBox, radio, button;
  777.     ObjPtr var;
  778.  
  779.     int enabledSources;
  780.  
  781.     /*Check out the enabled sources*/
  782.     MakeVar(object, ENABLEDSOURCES);
  783.     var = GetIntVar("AddFrameControls", object, ENABLEDSOURCES);
  784.     if (var)
  785.     {
  786.     enabledSources = GetInt(var);
  787.     }
  788.     else
  789.     {
  790.     enabledSources = FB_VIDEO;
  791.     }
  792.  
  793.     /*Add FrameRate label*/
  794.     textBox = TemplateTextBox(FramesTemplate, "Frame Rate Label", ONE_LINE, "Frame Rate:");
  795.     PrefixList(panelContents, textBox);
  796.     SetVar(textBox, PARENT, panelContents);
  797.  
  798.     /*Add text box*/
  799.     textBox = TemplateTextBox(FramesTemplate, "Frame Rate", EDITABLE + WITH_PIT + ONE_LINE, "");
  800.     PrefixList(panelContents, textBox);
  801.     SetVar(textBox, PARENT, panelContents);
  802.     AssocTextRealControlWithVar(textBox, object, FRAMERATE, 0.0, plusInf, TR_NE_BOTTOM);
  803.     SetTextAlign(textBox, RIGHTALIGN);
  804.     SetVar(textBox, HELPSTRING, NewString("This text box controls the frame rate in frames \
  805. per second used to control the video recorder.  Full speed frame rate for NTSC video \
  806. as used in the USA and Japan is 30 frames per second.*  PAL and SECAM video use \
  807. 25 frames per second, and motion picture recording uses 24 frames per second.  Edit \
  808. the text and press the Enter key to change the frame rate.\n\n\
  809. *Actually, NTSC frame rate is 29.97 frames per second, but most people call it \
  810. 30 to make it easier to deal with.  The 1% difference is not enough to notice \
  811. for most practical purposes.  You can use non-integral frame \
  812. rates if you like, but it is usually not worth the bother."));
  813.  
  814.     /*Add fps label*/
  815.     textBox = TemplateTextBox(FramesTemplate, "FPS Label", ONE_LINE, "frames per second (fps)");
  816.     PrefixList(panelContents, textBox);
  817.     SetVar(textBox, PARENT, panelContents);
  818.  
  819.     /*Add source title box*/
  820.     titleBox = TemplateTitleBox(FramesTemplate, "Frame Source");
  821.     PrefixList(panelContents, titleBox);
  822.     SetVar(titleBox, PARENT, panelContents);
  823.  
  824.     /*Make radio button group*/
  825.     radio = NewRadioButtonGroup("Frame Source Radio");
  826.     PrefixList(panelContents, radio);
  827.     SetVar(radio, PARENT, panelContents);
  828.     AssocDirectControlWithVar(radio, object, FRAMESOURCE);
  829.  
  830.     /*Make radio buttons*/
  831.     button = TemplateRadioButton(FramesTemplate, "Video Signal");
  832.     AddRadioButton(radio, button);
  833.     ActivateButton(button, enabledSources & FB_VIDEO ? true : false);
  834.     SetVar(button, HELPSTRING, NewString("When this button is down, the frame \
  835. for the recorder is taken directly off the video signal.  Because this may go through \
  836. a scan converter, the size of the frame can vary depending on the settings of the \
  837. converter."));
  838.  
  839.     button = TemplateRadioButton(FramesTemplate, "Window");
  840.     AddRadioButton(radio, button);
  841.     ActivateButton(button, enabledSources & FB_WINDOW ? true : false);
  842.     SetVar(button, HELPSTRING, NewString("When this button is down, the frame \
  843. for the recorder is taken from the window to record.  When there is more \
  844. than one window, such as when recording an animation from several visualization \
  845. windows, a rectangle enclosing all the windows is used."));
  846.  
  847.     button = TemplateRadioButton(FramesTemplate, "Fixed Frame");
  848.     AddRadioButton(radio, button);
  849.     ActivateButton(button, enabledSources & FB_SCREEN ? true : false);
  850.     SetVar(button, HELPSTRING, NewString("When this button is down, the frame \
  851. for the recorder is taken from a section of the screen with its origin at the \
  852. lower left of the screen.  The width and height are controlled by the values within \
  853. the text boxes to the right."));
  854.  
  855.     /*Add width text box*/
  856.     textBox = TemplateTextBox(FramesTemplate, "Frame Height", EDITABLE + WITH_PIT + ONE_LINE, "");
  857.     PrefixList(panelContents, textBox);
  858.     SetVar(textBox, PARENT, panelContents);
  859.     AssocTextIntControlWithVar(textBox, object, FRAMEHEIGHT, 0.0, plusInf, TR_NE_BOTTOM + TR_INT_ONLY);
  860.     SetTextAlign(textBox, RIGHTALIGN);
  861.     ActivateTextBox(textBox, enabledSources & FB_SCREEN ? true : false);
  862.     SetVar(textBox, HELPSTRING, NewString("This text box controls the height \
  863. of the recording frame in screen pixels.  By default, this is set to the width of the Silicon Graphics \
  864. NTSC screen.  If you are using a scan converter instead of the NTSC mode, change this \
  865. to match the portion of the screen you wish to use.  \
  866. The recording frame always has its origin at the bottom left of the screen."));
  867.  
  868.     /*Add height text box*/
  869.     textBox = TemplateTextBox(FramesTemplate, "Frame Width", EDITABLE + WITH_PIT + ONE_LINE, "");
  870.     PrefixList(panelContents, textBox);
  871.     SetVar(textBox, PARENT, panelContents);
  872.     AssocTextIntControlWithVar(textBox, object, FRAMEWIDTH, 0.0, plusInf, TR_NE_BOTTOM + TR_INT_ONLY);
  873.     SetTextAlign(textBox, RIGHTALIGN);
  874.     ActivateTextBox(textBox, enabledSources & FB_SCREEN ? true : false);
  875.     SetVar(textBox, HELPSTRING, NewString("This text box controls the width \
  876. of the recording frame in screen pixels.  By default, this is set to the width of the Silicon Graphics \
  877. NTSC screen.  If you are using a scan converter instead of the NTSC mode, change this \
  878. to match the portion of the screen you wish to use.  \
  879. The recording frame always has its origin at the bottom left of the screen."));
  880.  
  881.     /*Add by label*/
  882.     textBox = TemplateTextBox(FramesTemplate, "by", ONE_LINE, "by");
  883.     PrefixList(panelContents, textBox);
  884.     SetVar(textBox, PARENT, panelContents);
  885.  
  886.     return ObjTrue;
  887. }
  888.  
  889. static ObjPtr AddCommControls(object, panelContents)
  890. ObjPtr object, panelContents;
  891. /*Adds controls appropriate to a communications object to panelContents*/
  892. {
  893.     ObjPtr titleBox, button, radio, var;
  894.     ObjPtr textBox;
  895.  
  896.     /*Make the port device editing box and label*/
  897.     textBox = TemplateTextBox(CommTemplate, "Port Device Text", 0, "Port Device:");
  898.     PrefixList(panelContents, textBox);
  899.     SetVar(textBox, PARENT, panelContents);
  900.  
  901.     textBox = TemplateTextBox(CommTemplate, "Port Device", EDITABLE + WITH_PIT + ONE_LINE, "");
  902.     PrefixList(panelContents, textBox);
  903.     SetVar(textBox, PARENT, panelContents);
  904.     SetVar(textBox, HELPSTRING, NewString("This text box controls the serial \
  905. port device used to control the video recorder.  Enter a new device and press \
  906. the Enter key to change it.\n\n\
  907. Each physical serial port on the computer is controlled by a software device \
  908. driver.  This serial port device needs to be set to the correct device \
  909. for the port you are using to drive your video recorder.  If you do not \
  910. know the correct device name, look at the label on the serial port connection \
  911. and consult the documentation for your computer."));
  912.     AssocDirectControlWithVar(textBox, object, PORTDEV);
  913.  
  914.     /*Make the radio buttons for baud rate*/
  915.     titleBox = TemplateTitleBox(CommTemplate, "Baud Rate");
  916.     SetVar(titleBox, PARENT, panelContents);
  917.     PrefixList(panelContents, titleBox);
  918.  
  919.     radio = NewRadioButtonGroup("Baud Rate Radio Buttons");
  920.     SetVar(radio, PARENT, panelContents);
  921.     PrefixList(panelContents, radio);
  922.     SetVar(radio, HELPSTRING, NewString("This radio button group controls the baud rate \
  923. for communication with the video recorder.  The baud rate must be set to the \
  924. same value that your video recorder uses.  If you do not know what this is, consult \
  925. the documentation for your video recorder."));
  926.  
  927.     button = TemplateRadioButton(CommTemplate, "300");
  928.     AddRadioButton(radio, button);
  929.     SetVar(radio, HELPSTRING, NewString("This radio button sets the baud rate to \
  930. 300 baud."));
  931.  
  932.     button = TemplateRadioButton(CommTemplate, "1200");
  933.     AddRadioButton(radio, button);
  934.     SetVar(radio, HELPSTRING, NewString("This radio button sets the baud rate to \
  935. 1200 baud."));
  936.  
  937.     button = TemplateRadioButton(CommTemplate, "2400");
  938.     AddRadioButton(radio, button);
  939.     SetVar(radio, HELPSTRING, NewString("This radio button sets the baud rate to \
  940. 2400 baud."));
  941.  
  942.     button = TemplateRadioButton(CommTemplate, "4800");
  943.     AddRadioButton(radio, button);
  944.     SetVar(radio, HELPSTRING, NewString("This radio button sets the baud rate to \
  945. 4800 baud."));
  946.  
  947.     button = TemplateRadioButton(CommTemplate, "9600");
  948.     AddRadioButton(radio, button);
  949.     SetVar(radio, HELPSTRING, NewString("This radio button sets the baud rate to \
  950. 9600 baud."));
  951.  
  952.     button = TemplateRadioButton(CommTemplate, "19200");
  953.     AddRadioButton(radio, button);
  954.     SetVar(radio, HELPSTRING, NewString("This radio button sets the baud rate to \
  955. 19200 baud."));
  956.  
  957.     AssocDirectControlWithVar(radio, object, BAUDRATE);
  958.  
  959.     return ObjTrue;
  960. }
  961.  
  962. static ObjPtr DrawExtraRecorderIcon(icon, x, y)
  963. ObjPtr icon;
  964. int x, y;
  965. /*Draws the extra stuff associated with an icon*/
  966. {
  967.     ObjPtr repObj;
  968.     repObj = GetVar(icon, REPOBJ);
  969.     if (repObj && repObj == curRecorder)
  970.     {
  971.     DrawIcon(x, y, ICONSTAR, 
  972.         (char *) 0, (char *) 0, 
  973.         UIRED, DI_DRAWFORE | DI_DRAWBACK);
  974.     }
  975.     return ObjTrue;
  976. }
  977.  
  978. static ObjPtr ActivateRecorder(recorder)
  979. ObjPtr recorder;
  980. /*Activates a recorder*/
  981. {
  982.     SetVar(curRecorder, APPEARANCE, ObjTrue);
  983.     curRecorder = recorder;
  984.     SetVar(curRecorder, APPEARANCE, ObjTrue);
  985.     return ObjTrue;
  986. }
  987.  
  988. static ObjPtr MakeRecIconAppearance(icon)
  989. ObjPtr icon;
  990. /*Makes an icon's appearance*/
  991. {
  992.     ImInvalid(icon);
  993.     SetVar(icon, APPEARANCE, ObjTrue);
  994.     return ObjTrue;
  995. }
  996.  
  997. void InitRecorders(void)
  998. /*Initializes the recorder system*/
  999. {
  1000.     ObjPtr icon;
  1001.     char *devName;
  1002.     ObjPtr recorder;
  1003.     ObjPtr snapshot;
  1004.  
  1005.     recorderClass = NewObject(NULLOBJ, 0L);
  1006.     SetVar(recorderClass, CLASSID, NewInt(CLASS_RECORDER));
  1007.     AddToReferenceList(recorderClass);
  1008.     SetMethod(recorderClass, SHOWCONTROLS, NewControlWindow);
  1009.     SetMethod(recorderClass, NEWCTLWINDOW, ShowRecorderControls);
  1010.     SetVar(recorderClass, DOUBLECLICK, NewString(OF_SHOW_CONTROLS));
  1011.     icon = NewIcon(0, 0, ICONFRAME, "Frames");
  1012.     SetVar(recorderClass, CONTROLICON, icon);
  1013.     SetVar(recorderClass, CANSAVESETTINGS, ObjTrue);
  1014.     SetVar(recorderClass, SAVEEXTENSION, NewString("recdvr"));
  1015.     SetMethod(recorderClass, SAVECPANEL, SaveSnapshotControls);
  1016.     SetMethod(recorderClass, SAVEALLCONTROLS, LogSnapshotControls);
  1017.     SetMethod(recorderClass, ADDCONTROLS, AddFrameControls);
  1018.     SetVar(recorderClass, FRAMERATE, NewReal(30));
  1019.     AddSnapVar(recorderClass, FRAMERATE);
  1020.     SetVar(recorderClass, FRAMEWIDTH, NewInt(VSCRWIDTH));
  1021.     AddSnapVar(recorderClass, FRAMEWIDTH);
  1022.     SetVar(recorderClass, FRAMEHEIGHT, NewInt(VSCRHEIGHT));
  1023.     AddSnapVar(recorderClass, FRAMEHEIGHT);
  1024.     SetVar(recorderClass, FRAMEOX, NewInt(0));
  1025.     SetVar(recorderClass, FRAMEOY, NewInt(0));
  1026.     SetMethod(recorderClass, ACTIVATEOBJECT, ActivateRecorder);
  1027.     SetVar(recorderClass, FRAMESOURCE, NewInt(FS_VIDEO));
  1028.     SetVar(recorderClass, ENABLEDSOURCES, NewInt(FB_VIDEO));
  1029.     AddSnapVar(recorderClass, FRAMESOURCE);
  1030.  
  1031.     icon = NewIcon(0, 0, ICONRECORDER, "?");
  1032.     SetMethod(icon, ICONEXTRADRAW, DrawExtraRecorderIcon);
  1033.     SetVar(icon, HELPSTRING, NewString("This icon represents a video recorder \
  1034. driver.  Recorder drivers are used to do frame-by-frame recording from a script.  \
  1035. The active recorder driver is indicated by a red pilot light on the icon.  \
  1036. To change the active recorder, select it and press the Activate button.  To \
  1037. show controls for any of the recorders, select them and press the Show Controls \
  1038. button."));
  1039.     SetVar(recorderClass, DEFAULTICON, icon);
  1040.     DeclareIndirectDependency(icon, APPEARANCE, REPOBJ, APPEARANCE);
  1041.     SetMethod(icon, APPEARANCE, MakeRecIconAppearance);
  1042.  
  1043.     commRecorderClass = NewObject(recorderClass, 0L);
  1044.     AddToReferenceList(commRecorderClass);
  1045.     SetVar(commRecorderClass, NAME, NewString("Communication"));
  1046.     SetVar(commRecorderClass, BAUDRATE, NewInt(4));    /*9600 baud*/
  1047.     SetMethod(commRecorderClass, ADDCONTROLS, AddCommControls);
  1048.     icon = NewIcon(0, 0, ICONCOMM, "Communications");
  1049.     SetVar(commRecorderClass, CONTROLICON, icon);
  1050.     devName = getenv("SCIAN_RECORDER_DEV");
  1051.     if (!devName || !devName[0])
  1052.     {
  1053.     }
  1054.     else
  1055.     {
  1056.     SetVar(commRecorderClass, PORTDEV, NewString(devName));
  1057.     }
  1058.  
  1059.  
  1060.     devName = getenv("SCIAN_RECORDER_DEV");
  1061.     if (!devName || !devName[0])
  1062.     {
  1063.     devName = "/dev/ttyd4";
  1064.     }
  1065.     SetVar(commRecorderClass, PORTDEV, NewString(devName));
  1066.  
  1067.     AddSnapVar(commRecorderClass, BAUDRATE);
  1068.     AddSnapVar(commRecorderClass, PORTDEV);
  1069.  
  1070.     InitLVR5000();
  1071.     InitTQ2026F();
  1072.     InitScrDump();
  1073.     InitPostScript();
  1074. #ifdef JPEGRECORDER
  1075.     InitJpeg();
  1076. #endif
  1077. }
  1078.  
  1079. void KillRecorders(void)
  1080. /*Gets rid of all the recorders*/
  1081. {
  1082. #ifdef JPEGRECORDER
  1083.     KillJpeg();
  1084. #endif
  1085.     KillPostScript();
  1086.     KillScrDump();
  1087.     KillTQ2026F();
  1088.     KillLVR5000();
  1089.     RemoveFromReferenceList(commRecorderClass);
  1090.     RemoveFromReferenceList(recorderClass);
  1091. }
  1092.